package com.zq.it.service.impl.admin;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.List;

import com.zq.it.pojo.Netcourse;
import com.zq.it.service.admin.NetCourseService;
import com.zq.it.service.common.BaseServiceImpl;


public class NetCourseServiceImpl extends BaseServiceImpl implements NetCourseService{

	//private List<Netcourse> NETCLIST; //存储查询数据
	
	/*@Override
	public void removeNetcourse(Integer id) {
		getNetCourseDao().deleteNetcourseEtyByID(id);
		// TODO Auto-generated method stub	
	}*/

	@Override
	public void renewalNetcourse(Netcourse netcourse) {
        getNetCourseDao().updateNetcourseEty(netcourse);
	}
	@Override
	public List findNetCourseType() {
		return getNetCourseDao().findCourseTypes();
	}
	@Override
	public List getNetcourse(Integer id) {
		return getNetCourseDao().findNetcourseEtyById(id);
	}

	@Override
	public boolean addNetcourse( Netcourse netcourse,final String ffmpegPath,final String tmpFile,final String netcoursePicPath){
	
		 try {			
				File file=new File(tmpFile);
				if(file.exists()){									   			      
				   netcourse.setSize(file.length()/1024/1024f);					  
			       getNetCourseDao().saveNetcourseEty(netcourse);	
				}						   
					executeCodecs(ffmpegPath,tmpFile,netcoursePicPath);
					return true;
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					 return false;
				}
					
	}
	
	@Override
	public List getNetcourseByExmp(Netcourse netcourse) {
		// TODO Auto-generated method stub
		return getNetCourseDao().findNetcourseEtyByExmp(netcourse);
	}

	@Override
	public void removeNetcourse(Netcourse netcourse){
		// TODO Auto-generated method stub
		getNetCourseDao().deleteNetcourseEtyByObj(netcourse);
	}

	@Override
	public void removeAllNetcourse(Integer [] ids){
		getNetCourseDao().deleteNetcourseEtyListByIds(ids);
		// TODO Auto-generated method stub
		
	}
	
	/*private List getListFromTemplate(int [] ids){
		//System.out.println(ids[0]);
		List list=new ArrayList();
	  for(Netcourse  t:NETCLIST){
		 for(int i=0;i<ids.length;i++)
			 if(t.getId()==ids[i])
		        list.add(t);
	  }
	//  System.out.println(list.size());
	  return list;
	}
		 */
	//数据的导出
	@Override
		public ByteArrayInputStream exportNetcourseList(String[] headTitle,java.util.List<?> list ){
			// TODO Auto-generated method stub
			return new ByteArrayInputStream(exportToExcel(list,headTitle,com.zq.it.tool.HeadTitle.EN_NETCHEAD.getArray(),"com.zq.it.pojo.Netcourse").toByteArray());
		}

	
	@Override
	public List<Netcourse> getNetcListByHQL(Netcourse netcourse){		
		StringBuilder sbd=new StringBuilder("from Netcourse where 1=1\n");
		if(netcourse!=null){			
		Object obj=null;
		if((obj=netcourse.getNetCourseName())!=null&&!"".equals(obj))
			sbd.append("and netCourseName like '%"+obj+"%'");
		if((obj=netcourse.getLecturer())!=null&&!"".equals(obj))
			sbd.append("and lecturer like '%"+obj+"%'");
		if((obj=netcourse.getUploadTime())!=null&&!"".equals(obj))
			sbd.append("and uploadTime='"+obj+"'");
		}
		// TODO Auto-generated method stub
		return getNetCourseDao().findNetcourseListByHQL(sbd.toString());
	}
	 @Override
	public List findNetCourseByType(String type) {
		 return getNetCourseDao().findNetCoursesByType(type);
	 }
	/*@Override
	public List getNetcourseListByType(int type, String parameter) {
		// TODO Auto-generated method stub
		return null;
	}*/
		
}
